package cn.IT.Nf.Test.Servlet;


import cn.IT.Nf.Test.Dao.Impl.StaffsDaoImpl;
import cn.IT.Nf.Test.Dao.StaffsDao;
import cn.IT.Nf.Test.Entity.Staffs;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/updateStaffs")
public class UpdateStaffsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Staffs staffs = new Staffs(
                Integer.parseInt(request.getParameter("id")),
                request.getParameter("name"),
                Integer.parseInt(request.getParameter("age")),
                request.getParameter("phone"),
                request.getParameter("sta_pos"),
                request.getParameter("add_time"),
                request.getParameter("update_time")
        );
        StaffsDao staffsDao = new StaffsDaoImpl();
        int result = staffsDao.update(staffs);
        PrintWriter out = response.getWriter();
        if (result > 0) {
            out.write("更新成功");
            out.flush();
            out.close();
        }else {
            out.write("更新失败");
            out.flush();
            out.close();
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
